package com.bidevalution.core.util;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;

/**
 * @author huyiqi
 * @date 2019/12/3
 */
public class Base64Util {
    private static final Logger log = LoggerFactory.getLogger(Base64Util.class);
    private static final String CHARSET_NAME = "UTF-8";

    public Base64Util() {
    }

    public static byte[] decryptBase64(String key) {
        return decryptBase64(key, CHARSET_NAME);
    }

    public static byte[] decryptBase64(String key, String charSet) {
        try {
            return Base64.decodeBase64(key.getBytes(charSet));
        } catch (UnsupportedEncodingException var2) {
            log.error(var2.getMessage(), var2);
            return null;
        }
    }

    public static String encryptBase64(byte[] key) {
        return new String(Base64.encodeBase64(key));
    }

    public static String encryptBase64(String key) {
        try {
            return new String(Base64.encodeBase64(key.getBytes(CHARSET_NAME)));
        } catch (UnsupportedEncodingException var2) {
            log.error(var2.getMessage(), var2);
            return null;
        }
    }
}
